package com.xu.chuang.show.service.impl;

import com.google.gson.Gson;
import com.xu.chuang.show.bean.Content;
import com.xu.chuang.show.bean.ContextType;
import com.xu.chuang.show.bean.ShowUser;
import com.xu.chuang.show.network.HttpUtil;
import com.xu.chuang.show.network.Json2T;
import com.xu.chuang.show.service.inte.MainBizReqService;
import com.xu.chuang.show.util.Config;
import com.xu.chuang.show.util.JoiningURL;

import java.util.List;

/**
 * Created by coder on 2016/8/7.
 * @author MagicRain
 */
public class MainBizReqImpl implements MainBizReqService{

    @Override
    public Content upContent(Content content) {
        String path = Config.baseURL + Config.upContent;
        Gson gson = new Gson();
        HttpUtil.post(path, gson.toJson(content));
        return null;
    }

    @Override
    public List<Content> searchScope(Double latitude, Double longitude, Long showUserId) {
        String path = Config.baseURL + Config.searchScope;
        path = JoiningURL.addURLParam(path, "latitude", latitude.toString());
        path = JoiningURL.addNextParam(path, "longitude", longitude.toString());
        path = JoiningURL.addNextParam(path, "showUserId", showUserId.toString());
        String dataString  = HttpUtil.get(path);
        return Json2T.getObs(dataString, Content.class);
    }

    @Override
    public List<Content> filterType(ContextType contextType, Double latitude, Double longitude, Long showUserId) {
        String path = Config.baseURL + Config.filterType;
        path = JoiningURL.addURLParam(path, "contextType", String.valueOf(contextType.ordinal()));
        path = JoiningURL.addNextParam(path, "latitude", latitude.toString());
        path = JoiningURL.addNextParam(path, "longitude", longitude.toString());
        path = JoiningURL.addNextParam(path, "showUserId", showUserId.toString());
        String dataString = HttpUtil.get(path);
        return Json2T.getObs(dataString, Content.class);
    }

    @Override
    public List<Content> findUserContent(Long showUserId) {
        String path = Config.baseURL + Config.findUserContent;
        path = JoiningURL.addURLParam(path, "showUserId" ,showUserId.toString());
        String dataString = HttpUtil.get(path);
        return Json2T.getObs(dataString, Content.class);
    }

    @Override
    public ShowUser getOtherUser(Long contentId) {
        String path  =Config.baseURL + Config.getUserMessageFromContent;
        path = JoiningURL.addURLParam(path, "contentId", contentId.toString());
        String dataString = HttpUtil.get(path);
        return Json2T.getOb(dataString, ShowUser.class);
    }
}
